<script language=javascript>
function add_tag()
{
  var a=prompt('Please enter a tag name','');
  if(a)
  {
    a=a.strip()
    if(a.length>0)
    {
    	for(i=0;i<$('article_tag_id').length;++i)
    		if($('article_tag_id').options[i].text==a)
    		{
	    		$('article_tag_id').value=$('article_tag_id').options[i].value;
    			return false;
    		}
    	$('tagname').value=a;
    	return true;
    }
  }
  return false;
}
</script>
<div id=subform><input id=tagname name=tagname type=hidden value=''></input></div>

<% form_for :article, 
            :url => {:controller=>'blogs',:action=>'update',:id=>@article.id}, 
            :html => { :method => :put } do |f| -%>
  <p>Title:<br /><%= f.text_field :title, :size => 60 %></p>
  <p>Synopsis:<br /><%= f.text_area :synopsis, :rows => 8, :cols => 90 %></p>
  <p>Body:<br /><%= f.text_area :body, :rows => 40, :cols => 90 %></p>
  <%- if logged_in? && (current_person.admin?) -%>
  <p>Category:<br />
  		    <%= f.collection_select :category_id, Category.find(:all), :id, :name, :include_blank => false %> 
  <p>Category 2:<br />
  		    <%= f.collection_select :categoryt_id, Categoryt.find(:all), :id, :name, :include_blank => true %> 
  <%- end -%>
  <p>Tag:<br />
    <%= f.collection_select :tag_id, 
          Tag.find(:all), :id, :name, :include_blank => true %><%= link_to_remote "Add a tag", 
       :url => {:controller=>'tags',:action => "add"},:method=>:get,:submit   => "subform",:condition =>"add_tag()"  %></p>
    <p>Media file:<br /><%= f.text_field :media_url, :size => 60,:id=>'media_url' %></p>
     <% if logged_in? && current_person.admin?%>        
  <p>Published? <%= f.check_box :published %></p>
    <%end%>
  <%= submit_tag 'Save' %> or <%= link_to 'Cancel', {:controller=>'articles',:action=>'admin'} %>
<% end -%>